<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include 'GeneralController.php';
class ReservationController extends GeneralController {

        /*
         * Index page
         */
        public function ajaxCommande()
	{
            if(isset($_POST["nbPlaces"], $_POST["id_client"], $_POST["id_ligne_voyage"])){
                $this->load->database();
                $this->load->model('Reservation');
                
                $id_r=$this->Reservation->save($_POST["id_client"], $_POST["id_ligne_voyage"],$_POST["nbPlaces"]);
                if($id_r){
                echo json_encode(array("idReservation"=>$id_r,"codeErreur"=>null));
                }else{
                    echo json_encode(array("idReservation"=>null,"codeErreur"=>2));
                }
            }else{
                echo json_encode(array("idReservation"=>null,"codeErreur"=>1));
            }
	}
        public function show($id)
        {
           $this->load->library('session');
            $this->load->database();
            //var_dump();
           $this->load->database();
           $this->load->model('Reservation');
           $this->load->model('Client');           
           $this->load->model('Voyage');
           $this->load->model('LigneVoyage');
           $reservation =$this->Reservation->getReservationById($id);
           if($this->session->userdata('id')){
                if($this->session->userdata('id') ==$reservation->id_client){
                    $lv=$reservation->getLigneVoyage();
                    $v=$lv->getVoyage();
                    $client = $reservation->getClient();
                    $this->loadLayoutView('reservation_show',array('reservation'=>$reservation,'lv'=>$lv,'v'=>$v,'client'=>$client));
                }else{
                    $this->loadLayoutView('error',array('errorMsg'=>"Vous n'avez pas les droits nécessaires pour consulter cette page!",'classAlertName'=>"alert-danger",));
                    // L'utilisateur regarde une reservation qui ne lui appartient pas.
                }
           }else{
                $this->loadLayoutView('error',array('errorMsg'=>"Vous devez être connecté pour accéder à cette page!",'classAlertName'=>"alert-warning",));
                // L'utilisateur n'est pas connecté
           }
        }
        
        
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */